package leetcode.每日一题;

import org.junit.Test;

/**
 * @author :songyaozhang
 * @date :Created 2021/8/23 20:07
 * @description :
 */
public class 获取生成数组中的最大值 {
  @Test
  public void test() {
    Solution solution = new Solution();

  }

  class Solution {
    public int getMaximumGenerated(int n) {
      if (n == 0) return 0;
      if (n == 1) return 1;
      int[] nums = new int[n + 1];
      nums[0] = 0;
      nums[1] = 1;
      int max = 1;
      for (int i = 2; i <= n; i++) {
        if (i % 2 == 0) {
          nums[i] = nums[i / 2];
        } else {
          int index = i / 2;
          nums[i] = nums[index] + nums[index + 1];
        }
        max = Math.max(max, nums[i]);
      }
      return max;
    }
  }


}
